//
//  CLTabBarController.m
//  Class_IOS
//
//  Created by peter on 14-8-29.
//  Copyright (c) 2014年 qiuyang. All rights reserved.
//

#import "CLTabBarController.h"

@interface CLTabBarController ()

@end

@implementation CLTabBarController


- (id)init
{
    self = [super init];
    if (self) {
        _tabBarEnabled = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark show and hide tabbar

+ (void)showTabBar:(UITabBarController *)tabBarController
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fScreenHeight = screenRect.size.height - 49.0;
    
    if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
        fScreenHeight = screenRect.size.width - 49.0;
    }
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];
    
    for (UIView *tabBarSubViews in tabBarController.view.subviews) {
        if ([tabBarSubViews isKindOfClass:[UITabBar class]]) {
            [tabBarSubViews setFrame:CGRectMake(tabBarSubViews.frame.origin.x, fScreenHeight, tabBarSubViews.frame.size.width, tabBarSubViews.frame.size.height)];
        } else {
            [tabBarSubViews setFrame:CGRectMake(tabBarSubViews.frame.origin.x, tabBarSubViews.frame.origin.y, tabBarSubViews.frame.size.width, fScreenHeight)];
        }
    }
    tabBarController.tabBar.hidden = NO;
    [UIView commitAnimations];
}

+ (void)hideTabBar:(UITabBarController *)tabBarController
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fScreenHeight = screenRect.size.height;
    
    if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
        fScreenHeight  = screenRect.size.width;
    }
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];
    
    for (UIView *tabBarSubViews in tabBarController.view.subviews) {
        if ([tabBarSubViews isKindOfClass:[UITabBar class]]) {
            [tabBarSubViews setFrame:CGRectMake(tabBarSubViews.frame.origin.x, fScreenHeight, tabBarSubViews.frame.size.width, tabBarSubViews.frame.size.height)];
        } else {
            [tabBarSubViews setFrame:CGRectMake(tabBarSubViews.frame.origin.x, tabBarSubViews.frame.origin.y, tabBarSubViews.frame.size.width, fScreenHeight)];
            //tabBarSubViews.backgroundColor = [UIColor redColor];
        }
    }
    tabBarController.tabBar.hidden = YES;
    [UIView commitAnimations];    
}

#pragma  mark overwrite tabbar mathod

- (void)setViewControllers:(NSArray *)viewControllers
{
    [super setViewControllers:viewControllers];
    
    if ([viewControllers count] > 0) {
        [self setSelectedIndex:0];
    }
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (_tabBarEnabled) {
        [super setSelectedIndex:selectedIndex];
    }
}


@end
